package Utility
{
	import Utility.DisplayLoader;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.controls.List;
	import mx.core.FlexGlobals;
	import mx.events.CloseEvent;
	import mx.events.ListEvent;
	
	import spark.components.TextInput;

	public class SmartTips extends List
	{   
		private var currMsg:String;//变动搜素文本前存的信息
		public var inputText:String;
		private var dataArray:Array;
		private var searList:List;
		private var inputValue:TextInput;
		public function SmartTips()
		{
	
			super();
		}
		
		/**
		 * 设置需要搜索的内容
		 * @param:内容数组
		 */   
		public function setSearchDatas(source:Array):void
		{
			//这里只是先存放起数据
			this.dataArray = source;
		}
		
		//输入文本内容变化事件
		public function inputChangeEvent(textInput:TextInput,searchList:List):void
		{
			
			//每次输入文字变化，都检索一下，查看数据是否变化
			if(currMsg != textInput.text)
			{
				currMsg = textInput.text;
				var seachData:ArrayCollection = new ArrayCollection();
				if(currMsg != "" && this.dataArray!=null)
				{
					//在这里分析所有的内容，找出符合的内容
					for(var i:int = 0; i < dataArray.length; i++)
					{
						//逐个检索,是否具有输入的内容，有则存放进去
						if(dataArray[i].indexOf(currMsg) == 0)
						{
							seachData.addItem(dataArray[i]);
						}
					}
				}
				//显示出与搜索相关的信息
	            
//				this.x=textInput.x;
//				this.y=textInput.y+22;
//				this.width=textInput.width;
//				this.height=170;
				searchList.visible=true;
				//this.includeInLayout=true;
				searchList.dataProvider=seachData;
				//显示是否有相关的搜索相关信息,如果没有就显示默认信息
				if(seachData.length == 0)
				{
					//seachData = defaultData;
					searchList.visible=false;
					searchList.includeInLayout=false;
				}
				searList=searchList;
     			inputValue=textInput;
			}
			
		}
		
		//相应list的点击事件
		public function itemChangEvent(event:ListEvent):void
		{   
			inputValue.text = String(searList.selectedItem);
			searList.visible = false;
			
		}
	}
}